package com.shujia.flink.transformaction

import org.apache.flink.api.scala._
import org.apache.flink.streaming.api.scala.StreamExecutionEnvironment
import org.apache.flink.streaming.api.windowing.time.Time

object Demo5WindowOperator {
  def main(args: Array[String]): Unit = {


    //创建flink  程序的入口  相当于sparkContext
    val env = StreamExecutionEnvironment.getExecutionEnvironment
    env.setParallelism(2)

    val ds = env.socketTextStream("node1", 8888)

    ds.flatMap(_.split(","))
      .map(w => (w, 1))
      .keyBy(_._1)
      //      .timeWindow(Time.seconds(5)) //滚动窗口
      .timeWindow(Time.seconds(5), Time.seconds(1)) //华东窗口
      .sum(1)
      .print()


    env.execute("KeyBy")


  }

  case class Student(id: String, name: String, age: Int, gender: String, clazz: String, i: Int)

}
